/***************************************************************************************
 * object_reflection.cpp
 * 描述：c++ 实现对象的反射机制,参考网络代码，添加注释
 * 作者: xhome
 * 时间:2020/5/20
 ***************************************************************************************/
#include <iostream>
#include "object_reflection.h"

class  BaseObject{
public:
    explicit BaseObject()= default;
    virtual void print(){
        std::cout << "BaseObject print ok." << std::endl;
    }

};

REGISTER(BaseObject);

class DriveA : public BaseObject{
public:
    void print() override {
       std::cout << "DriveA print ok." << std::endl;
    }

};
REGISTER(DriveA);

class DriveB : public BaseObject{
public:
    void print() override {
        std::cout << "DriveB print ok." << std::endl;
    }

};
REGISTER(DriveB);

int main()
{

    shared_ptr<BaseObject> p1((BaseObject *)Reflector::instance()->create_object("BaseObject"));
    p1->print();

    shared_ptr<DriveA>  p2((DriveA*)Reflector::instance()->create_object("DriveA"));
    p2->print();

    shared_ptr<DriveA>  p3((DriveA*)Reflector::instance()->create_object("DriveB"));
    p3->print();


    return 0;
}


